package com.mixue.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.orderservice.OrdersService;
import com.mixue.model.Goods;
import com.mixue.model.Orders;
import com.mixue.restful.ResoutSet;
import com.sun.org.apache.regexp.internal.RE;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RequestMapping("/order")
@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrdersService orderService;

    @GetMapping("/page")
    public ResoutSet<Page> page(int page, int pageSize){

        Page<Orders> pageInfo=new Page(page,pageSize);
        LambdaQueryWrapper<Orders> queryWrapper=new LambdaQueryWrapper();
//        queryWrapper.like(name!=null,Orders::getAmount,name);
        queryWrapper.orderByDesc(Orders::getOrderTime);
        Page<Orders> page1 = orderService.page(pageInfo, queryWrapper);
        return ResoutSet.sussess(pageInfo);
    }
@Transactional
    @PostMapping("/submit")
    public ResoutSet<String> submit(@RequestBody Orders orders) throws IOException {
        log.info("订单数据：{}", orders);
        orderService.submit(orders);
        return ResoutSet.sussess("支付成功");
    }
}